
var app=getApp()
var date = new Date();
const months = []
const days = []


var util = require('../../utils/util.js'); 


for (let i = 1; i <= 12; i++) {
  months.push(i)
}

for (let i = 1; i <= 31; i++) {
  days.push(i)
}

Page({
  data: {
    months: months,
    year:date.getFullYear(),
    month: date.getMonth() + 1,
    days: days,
    day: date.getDate(),
    value: [date.getMonth(), date.getDate()-1],
    count:0
  },

  onLoad:function(options){
    this.do_countByTargetDate()
  },

  bindChange: function (e) {
    var page=this;
    const val = e.detail.value
    this.setData({
      month: this.data.months[val[0]],
      day: this.data.days[val[1]]
    })
    page.do_countByTargetDate()
  },



  do_countByTargetDate: function () {
    var page = this
    wx.request({
      url: 'http://localhost:8080/kc4s/appointment/countByTargetDate', //仅为示例，并非真实的接口地址
      // 一定要x y
      data: {
        targetDate: page.data.year + '-' + page.data.month + '-' + page.data.day
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },

      method: "POST",
      success: function (res) {
        console.log(res.data)
        page.setData({count:res.data})
        //page.setData({count:})
      }
    })
  },



  do_addAppointment: function () {
    var page=this
    wx.request({
      url: 'http://localhost:8080/kc4s/appointment/add', //仅为示例，并非真实的接口地址
      // 一定要x y
      data: {
        customerPhoneNum: app.data.customer.phoneNum,
        targetDate: page.data.year + '-' +page.data.month + '-'+page.data.day
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },

      method: "POST",
      success: function (res) {
          console.log(res.data)
          page.do_countByTargetDate()   
      }
    })
  },


  check_weihu:function(){
    var page=this;
    var month=this.data.month;
    var day=this.data.day;
    wx.showModal({
      title: '请确认信息',
      content: '日期：'+month+"月"+day+"日",
      success: function (res) {
        if (res.confirm) {
        //  console.log('用户点击确定')
          page.do_addAppointment();
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 1000
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }


 




})